<?php

final class HomeController extends AbstractController {

    public $modelName = null;

    public function _Action() {
        Layout::getInstance()->setView('main', 'home', 'home');
        $this->content();
    }

    public static function errorAction($params) {
        SiteTitle::makeTitle('Home');
        $errorPage = URLManager::getErrorPage();
        if (!is_null($errorPage)) {
            LayoutManager::setVar('error', "Page not found: {$errorPage}", 'error');
            self::content();
        } else {
            URLManager::setPath('home');
            URLManager::redirect();
        }
    }

    public static function content() {
        Loader::includeFile('model', 'NewsModel');
        $news = NewsModel::getLast(5);
        $newsHome = array();
        foreach ($news as $NewsModel) {
            $newsHome[] = array(
                'title' => $NewsModel->getTitle(),
                'link' => array('controller' => 'news', 'action' => 'view', 'params' => array($NewsModel->getId()))
            );
        }
        Layout::getInstance()->set('newsHome', $newsHome);
    }

}

?>
